package com.java.al.thread;

public class MyThread implements Runnable {
	Timer time = new Timer();

	@Override
	public void run() {
		// for (int i = 0; i < 100; i++) {
		// System.out.println("Thread:-----"+i);
		// }
		time.add(Thread.currentThread().getName());
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		MyThread my = new MyThread();
		Thread t1 = new Thread(my);
		Thread t2 = new Thread(my);
		t1.setName("First");
		t2.setName("Second");
		t1.start();
		t2.start();
		for (int i = 0; i < 100; i++) {
			// System.out.println("Main:====="+i);
		}
	}

}

class Timer {
	private static int num = 0;

	public void add(String name) {
		synchronized (this) {
			num++;
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
			}
			System.out.println("you are the " + num
					+ " user and the the Thread Name is " + name);
		}
	}
}